package com.clouddot.baipai.ui.fragment.V_MainFragment;

import android.content.Context;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.clouddot.baipai.R;
import com.clouddot.baipai.infrastructure.environment.Env;
import com.clouddot.baipai.model.beam.getPersonInfo.getPersonInfoResponse;
import com.clouddot.baipai.ui.fragment.BaseFragment;
import com.clouddot.baipai.ui.util.ToastUtil;

/**
 * Created by wxy on 2018/4/10.
 */

public class V_MineFragment extends BaseFragment {

    private View view;
    private Context context;

    private LinearLayout data;
    private RelativeLayout scanCard;
    private ImageView imageView;
    private TextView name,className,tel,email  ,sex;

    @Override
    public void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    }

    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {

        return view;
    }

    @Override
    protected void setContentView() {
        super.setContentView();
            view = LayoutInflater.from(context).inflate(R.layout.v_f_minefg,null);

    }

    @Override
    protected void initControls() {
        super.initControls();
        scanCard = view.findViewById(R.id.scanCard);
        data = view.findViewById(R.id.data);
        name = view.findViewById(R.id.name);
        className = view.findViewById(R.id.className);
        sex = view.findViewById(R.id.sex);
        tel = view.findViewById(R.id.tel);
        email = view.findViewById(R.id.emal);
        imageView = view.findViewById(R.id.image);
        data.startAnimation(animation3);

    }


    @Override
    protected void setListener() {
        super.setListener();

    }


    @Override
    protected void loadParams() {
        super.loadParams();
    }

    @Override
    public void onAttach(Context context) {
        this.context = context;
        super.onAttach(context);
    }

    @Override
    public void onResume() {
        super.onResume();
        if(Env.getAppContext().isInitial) {
            if (Env.getAppContext().StudentId != null) {
                data.setVisibility(View.VISIBLE);
                scanCard.setVisibility(View.GONE);

                runThreadAction();

            } else {
                data.setVisibility(View.GONE);
                scanCard.setVisibility(View.VISIBLE);
                scanCard.startAnimation(animation3);
            }
        }
    }

    @Override
    public void runThreadAction() {
        super.runThreadAction();
    }

    @Override
    protected Object runThreadActionExceute() {
         super.runThreadActionExceute();
        return Env.getAppPresenter().getPersonInfo();
    }

    @Override
    protected void runThreadActionSuccess(Object result) {
        super.runThreadActionSuccess(result);
        getPersonInfoResponse response = (getPersonInfoResponse) result;
        if(response.isSuccess()){
            Glide.with(context).load(Env.getAppContext().IP+response.Photo)
                    .placeholder(R.drawable.imageload).error(R.drawable.img_02).into(imageView);
            name.setText(response.RealName);
            className.setText("班级：" +response.ClassName);
            sex.setText("性别："+response.Sex);
            tel.setText("电话："+response.Mobile);
            email.setText("邮箱："+response.Email);
        }else{
            ToastUtil.showToast(context,"个人信息获取失败");
        }
    }

    @Override
    protected void runThreadActionError(Exception ex) {
        super.runThreadActionError(ex);
    }


}
